﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TKToXML.Models;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;

namespace TKToXML.Persistence.ClassMaps
{
    public class LopMap : ClassMapping<Lop>
    {
        public LopMap()
        {
            ComposedId(lop =>
            {
                lop.Property(x => x.Id, map => map.Column("Id"));
                lop.Property(x => x.Nam, map => map.Column("Nam"));
            });

            //Id(x => x.Id, map => map.Generator(Generators.GuidComb));
            Property(x => x.Name);

            Bag(x => x.SinhViens,
                map =>
                {
                    map.Table("SinhVien");
                    map.Key(k => 
                        {                             
                            //k.Column("LopId");
                            //k.Column(a => a.Name("LopNam"));
                            //k.Column(a => a.Name("LopId"));
                            k.Columns(c1 => c1.Name("LopId"), c2 => c2.Name("LopNam"));
                        });
                    map.Cascade(Cascade.All);
                    map.Inverse(true);
                }
                ,
                x => x.OneToMany(sv =>
                {                   
                    //sv.Class(new SinhVien().GetType());                    
                    sv.Class(typeof(SinhVien));
                })
            );

        }
    }
}
